package com.kgc.scd.util;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Collection;

/**
 * Created On : 2022/5/13.
 * <p>
 * Author : zhukang
 * <p>
 * Description: 分页返回实体类
 */
@Data
public class PageSupport<T> {

    /**
     * 分页页码
     */
    private int pageNo;

    /**
     * 分页条数
     */
    private int pageSize;

    /**
     * 总条数
     */
    private int totalCount;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 当前分页数据
     */
    private Collection<T> pageData;

    /**
     * 分页页码处理
     */
    public void setPageNo(int pageNo) {
        if(pageNo < 1){
            pageNo = 1;
        }
        this.pageNo = pageNo;
    }

    /**
     * 分页条数处理
     */
    public void setPageSize(int pageSize) {
        if(pageSize < 1){
            pageSize = 1;
        }
        this.pageSize = pageSize;
    }

    /**
     * 当总条数确定时，总页数也是可以确定的
     */
    public void setTotalCount(int totalCount) {
        if(totalCount > 0){
            this.totalCount = totalCount;
            this.totalPage = this.totalCount % this.pageSize == 0
                    ? this.totalCount / this.pageSize
                    : this.totalCount / this.pageSize + 1;
        }
    }
}
